/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-10-27
 * Time: 19:20
 */
public class test_2 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param arr int整型一维数组 the array
     * @return int整型
     */
    public int maxLength(int[] arr) {
        int n = arr.length;
        int max = 0;
        int left = 0;
        int[] fig = new int[100001];
        for (int right = 0; right < n; right++) {
            fig[arr[right]]++;
            while (fig[arr[right]] != 1 && left < right) {
                fig[arr[left]]--;
                left++;
            }
            max = Math.max(max, right - left + 1);
        }
        return max;
    }

    public static void main(String[] args) {
        test_2 test = new test_2();
        System.out.println(test.maxLength(new int[]{2, 2, 3, 4, 8, 99, 3}));
    }
}
